package com.company.xiaomiex;

import java.util.*;

public class TreeHeight {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n < 3){
            System.out.println(n);
        }else{
            int[] height = new int[n];
            int[] binary = new int[n];
            height[0] = 1;
            int maxHeight = 0;
            for (int i = 0; i < n - 1; i++) {
                int parent = sc.nextInt();
                int child = sc.nextInt();
                // 每个结点的子树个数
                binary[parent]++;
                if(binary[parent] < 3){
                    height[child] = height[parent] + 1;
                }
                maxHeight = Math.max(maxHeight,height[child]);
            }
            System.out.println(maxHeight);
        }

    }


}
